//'你的token'
const token = import.meta.env.VITE_TIANDITU_KEY
//负载均衡解决天地图调用经典底图切片加载丢失，418与404报错问题
const servers = [...Array(8).keys()]
const rand = (min = 0, max = 1) => Math.round(Math.random() * (max - min) + min)
const serversProxy: any = new Proxy(servers, {
  get(target, prop: any) {
    if (prop === 'server') {
      return target[rand(1, target.length - 1)]
    }
    return target[prop]
  },
})
const tiandituHeader = 'https://t' + serversProxy.server + '.tianditu.gov.cn/'
const tiandituCenter =
  '/wmts?&SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER='
const tiandituEnd =
  '&STYLE=default&TILEMATRIXSET=w&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=tiles&tk='
export const baseMapLayer = {
  影像: {
    map: {
      source: {
        id: 'tdtImg',
        source: {
          type: 'raster',
          tiles: [
            tiandituHeader +
              'img_w' +
              tiandituCenter +
              'img' +
              tiandituEnd +
              token,
          ],
          tileSize: 256,
        },
      },
      layer: {
        id: 'tdtImg',
        type: 'raster',
        source: 'tdtImg',
        minzoom: 0,
        maxzoom: 17,
      },
    },
    note: {
      source: {
        id: 'tdtCia',
        source: {
          type: 'raster',
          tiles: [
            tiandituHeader +
              'cia_w' +
              tiandituCenter +
              'cia' +
              tiandituEnd +
              token,
          ],
          tileSize: 256,
        },
      },
      layer: {
        id: 'tdtCia',
        type: 'raster',
        source: 'tdtCia',
        minzoom: 0,
        maxzoom: 17,
      },
    },
  },
  经典: {
    map: {
      source: {
        id: 'tdtVec',
        source: {
          type: 'raster',
          tiles: [
            tiandituHeader +
              'vec_w' +
              tiandituCenter +
              'vec' +
              tiandituEnd +
              token,
          ],
          tileSize: 256,
        },
      },
      layer: {
        id: 'tdtVec',
        type: 'raster',
        source: 'tdtVec',
        minzoom: 0,
        maxzoom: 17,
      },
    },
    note: {
      source: {
        id: 'tdtCva',
        source: {
          type: 'raster',
          tiles: [
            tiandituHeader +
              'cva_w' +
              tiandituCenter +
              'cva' +
              tiandituEnd +
              token,
          ],
          tileSize: 256,
        },
      },
      layer: {
        id: 'tdtCva',
        type: 'raster',
        source: 'tdtCva',
        minzoom: 0,
        maxzoom: 17,
      },
    },
  },
  地形: {
    map: {
      source: {
        id: 'tdtTer',
        source: {
          type: 'raster',
          tiles: [
            tiandituHeader +
              'ter_w' +
              tiandituCenter +
              'ter' +
              tiandituEnd +
              token,
          ],
          tileSize: 256,
        },
      },
      layer: {
        id: 'tdtTer',
        type: 'raster',
        source: 'tdtTer',
        minzoom: 0,
        maxzoom: 17,
      },
    },
    note: {
      source: {
        id: 'tdtCta',
        source: {
          type: 'raster',
          tiles: [
            tiandituHeader +
              'cta_w' +
              tiandituCenter +
              'cta' +
              tiandituEnd +
              token,
          ],
          tileSize: 256,
        },
      },
      layer: {
        id: 'tdtCta',
        type: 'raster',
        source: 'tdtCta',
        minzoom: 0,
        maxzoom: 17,
      },
    },
  },
}
